package main

import (
	"context"
	"fmt"
	"maya-service/lib/authentication"
	"maya-service/utils"

	"maya-service/assistant"
	"maya-service/bll"
	"maya-service/client"
	"maya-service/collector"
	"maya-service/config"
	"maya-service/event"
	"maya-service/server"
	"maya-service/store"
)

type InitFunc func() func()

func main() {
	var (
		// system init func
		bootstraps = []InitFunc{
			config.Init,
			collector.Init,
			server.Init,
			client.Init,
			store.Init,
			assistant.Init,
			bll.Init,
			authentication.Init,
		}
	)

	event.Init()
	for _, bootstrap := range bootstraps {
		cancel := bootstrap()
		event.Subscribe(event.EventExit, func(ctx context.Context, e event.Event, payload interface{}) {
			cancel()
		})
	}

	//bll.ScanAllUser()
	go func() {
		defer utils.ExceptionCatch()
		bll.AiQuestion.RefreshGuideAnswer()
		bll.ScanAllUserAiQuestionRank()
	}()

	fmt.Println(config.MicroService.Run())
}
